# Maintainer: Justin Kromlinger <hashworks@archlinux.org>
# Contributor: Ivan <vantu5z@mail.ru>

pkgname=wireproxy
pkgver=1.0.5
pkgrel=3
arch=(loong64 x86_64)
license=(ISC)
url="https://github.com/octeep/wireproxy"
pkgdesc="Wireguard client that exposes itself as a socks5 proxy"
depends=('glibc')
makedepends=('go')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/refs/tags/v${pkgver}.tar.gz"
        "${pkgname}.sysusers"
        "${pkgname}.tmpfiles"
        "${pkgname}.service"
        "${pkgname}@.service"
        "${pkgname}-user.service"
        "${pkgname}-user@.service")
sha256sums=('3779a157713b462a7b5322f1437f768ab69ae446df0ceca76c6dff7c4030e425'
            '24a30e40d3fb5d79b81b2028b17533abf1e27cb9684035ba19c639f6c45907d2'
            'ab9a59d0f200371aee18abc93653cf8f9504063d14ae08e289b90f711e559735'
            '2386e40a6b1999341907262abc0f6e62d9a2d02706a497d619664b4c43cf852f'
            'b72ca8f8716d2eea9eb782ffa11942e6a44b2e8e9ec7b60e96565b8f29731276'
            '9c136bca0f65070f450ce942be7cd48254a385ed2a286f792d22ab74bb9a29a2'
            'fae5f0e1669d05d10b13a00031132c9bde8cc9b3e22fc91154edd5c01d750ef3')

build() {
  cd "${pkgname}-${pkgver}"

  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"

  go build -v \
    -buildmode=pie \
    -trimpath \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode=external \
      -X main.version=${pkgver}" \
    -o "${pkgname}" \
    "./cmd/${pkgname}"
}

package() {
  install -Dm0644 "${pkgname}.sysusers" "${pkgdir}/usr/lib/sysusers.d/${pkgname}.conf"
  install -Dm0644 "${pkgname}.tmpfiles" "${pkgdir}/usr/lib/tmpfiles.d/${pkgname}.conf"
  install -Dm0644 "${pkgname}.service" "${pkgname}@.service" -t "${pkgdir}/usr/lib/systemd/system/"
  install -Dm0644 "${pkgname}-user.service" "${pkgdir}/usr/lib/systemd/user/${pkgname}.service"
  install -Dm0644 "${pkgname}-user@.service" "${pkgdir}/usr/lib/systemd/user/${pkgname}@.service"

  cd "${pkgname}-${pkgver}"
  install -Dm0755 "${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
  install -Dm0644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
